package com.qing.thread.safelist;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * JUC包有个List是线程安全的
 */
public class SafeList {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> copyOnWriteArrayList = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(() -> {
                copyOnWriteArrayList.add(Thread.currentThread().getName());
            }).start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(copyOnWriteArrayList.size());
    }

}
